package com.lsp.microarticle.article.controller;

import com.lsp.microarticle.article.params.AddArticleParam;
import com.lsp.microarticle.article.params.ArticleSearchParam;
import com.lsp.microarticle.article.service.ArticleService;
import com.lsp.microcommon.annotation.NoLogin;
import com.lsp.microcommon.common.CommonResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/app/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @PostMapping("/add")
    public CommonResult addArticle(@RequestBody AddArticleParam param){
        articleService.addArticle(param);
        return CommonResult.success();
    }

    @NoLogin
    @PostMapping("/upload/img")
    public CommonResult uploadImg(MultipartFile file){
        return CommonResult.success(articleService.uploadImg(file));
    }

//    @NoLogin
//    @PostMapping("/page")
//    public CommonResult articlePageInfo(@RequestBody ArticlePageParam param){
//        PageVo<Article> articlePageVo = articleService.articlePageInfo(param);
//        return CommonResult.success(articlePageVo);
//    }

    @PostMapping("/page")
    public CommonResult articlePageInfo(@RequestBody ArticleSearchParam param){
        return CommonResult.success(articleService.articlePage(param));
    }

    @GetMapping("/info")
    public CommonResult articleInfo(Integer articleId){
        return CommonResult.success(articleService.selectInfoById(articleId));
    }

    @GetMapping("/rank")
    public CommonResult articleRank(Integer count){
        return CommonResult.success(articleService.articleRank(count));
    }
}
